//
//  TabbarViewController.m
//  AnimationRecommend
//
//  Created by ljm on 2017/2/14.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "TabbarViewController.h"

#import "HomePageViewController.h"
#import "EvaluateViewController.h"
#import "MusicViewController.h"
#import "MixCellsViewController.h"

@interface TabBarViewController ()

@property(nonatomic,strong) NSMutableArray <UIViewController *>*childVCs;

@end

@implementation TabBarViewController

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.tabBar.tintColor = tabbarTintColor;
        self.tabBar.backgroundColor  = [UIColor lightGrayColor];
        self.tabBar.barTintColor = tabbarBarTintColor;
        self.tabBar.alpha = 0.9;
        self.tabBar.opaque = YES;
        self.tabBar.translucent = NO;
        
        self.childVCs = [NSMutableArray array];
        [self addChildVcs];
    }
    return self;
}

- (void)addChildVcs {
    [self addChildVcWithTitle:@"主页" andClassName:@"HomePageViewController" andNormalImageName:@"shop" andSelectedImageName:@"shop-2"];
    [self addChildVcWithTitle:@"资讯" andClassName:@"EvaluteViewController" andNormalImageName:@"notebook" andSelectedImageName:@"notebook-2"];
    [self addChildVcWithTitle:@"社区" andClassName:@"MusicViewController" andNormalImageName:@"chat" andSelectedImageName:@"chat-3"];
    [self addChildVcWithTitle:@"我的" andClassName:@"MixCellsViewController" andNormalImageName:@"boy" andSelectedImageName:@"boy-2"];
}

- (void)addChildVcWithTitle:(NSString *)title andClassName:(NSString *)className andNormalImageName:(NSString *)normalImageName andSelectedImageName:(NSString *)selectedImageName {
    
    UIImage *imageNormal = [UIImage imageNamed:normalImageName];
    imageNormal = [imageNormal  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *imageSelected = [UIImage imageNamed:selectedImageName];
    imageSelected = [imageSelected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIViewController *vc = [[NSClassFromString(className) alloc]init];
    vc.tabBarItem = [[UITabBarItem alloc]initWithTitle:title image:imageNormal selectedImage:imageSelected];
    vc.title = title;

    UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
    
    [self.childVCs addObject:nvc];

    self.viewControllers = self.childVCs;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
